/*
	Copyright Christopher Diggins 2008
	Licensed under LGPL version 3.0
	http://cppscript.googlecode.com

*/

namespace misc
{
	var RepeatStr(var v, var n) {
		var r = "";
		for (var i=0; i < n; ++i) {
			r += v;
		}
		return r;
	}	
}

namespace sexpr
{
	var Nil() {
		return list();
	}

	var IsAtom(var x) {
		return x.size() == 1;
	}

	var IsNull(var x) {
		return !x;
	}

	var Tail(var x) {
		return tail(x);
	}

	var Head(var x) {
		return x.front();
	}

	var Cons(var x, var y) {
		y.push_front(x);
		return y;
	}

	var Print(var node, var depth = 0) {
		var r = misc::RepeatStr("  ", depth);
		if (node.size() == 0) {
			return r + node;
		}
		else {
			r = "\n" + r + "(" + Head(node);
			foreach (x, Tail(node)) {
				r += Print(x, depth + 1) + " ";
			}
			r += ")";
			return r;
		}
	}
}
